package commit

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"practice/config"
	"practice/internal/model/dao"
)

type Finds struct {
	UserId   int `form:"userId" json:"userId" xml:"userId"  binding:"required"`
	TravelId int `form:"travelId" json:"travelId" xml:"travelId" binding:"required"`
}

func FindsCommit(c *gin.Context) {
	var json Finds
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	userId := json.UserId
	travelId := json.TravelId
	var commits dao.UserCommit
	config.DB.Where("user_id=? and travel_id=?", userId, travelId).First(&commits)
	if commits.ID == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"error": "没有该评论"})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"msg":  "查询成功",
		"data": commits,
	})
}
